{extend name="admin/b2c/base" /}
{block name="resources"/}
<link rel="stylesheet" type="text/css" href="ADMIN_CSS/product.css">
<script type="text/javascript" src="__STATIC__/My97DatePicker/WdatePicker.js"></script>
<style type="text/css">
.tr-title {
	height: 30px;
	background: #E3E3E3;
	border:1px solid rgba(234, 233, 233, 0.51);
}

.fun-a {
	margin-top: 0px;
	padding: 6px 15px 0 15px;
}

.a-pro-view-img {
	float: left;
}

.thumbnail-img {
	width: 60px;
	margin-right: 10px;
}

.cell i {
	display: block;
}
.remodal-bg.with-red-theme.remodal-is-opening,.remodal-bg.with-red-theme.remodal-is-opened {
      filter: none;
}

.remodal-overlay.with-red-theme {
      background-color: #f44336;
}

.remodal.with-red-theme {
      background: #fff;
}

input[type="radio"], input[type="checkbox"] {
    margin: -1px 5px 0;
	margin-left:0px;
}
.edit-group{
	border-bottom: 1px solid #ebebeb;
	margin-bottom:10px;
}
.edit-group label{	
	font-weight:normal;
}
.edit-group-title{
	height:15px;
	line-height:15px;
	width:140px;
	margin-top:3px;
	margin-bottom:3px;
}
.edit-group-button{	   
    border-color: #3283fa;
	border: 1px solid #bbb;
	height: 26px;
    line-height: 24px;
    padding: 0 5px;
}
.group-button-bg{
	 background: #3283fa;
	 color: #fff;
}
.div-pro-view-name{width:75%;}
i.hot,i.recommend,i.new{font-size:12px;margin-right:10px;font-style:normal;color:#fff;background-color:#E84C3D;border-radius:2px;padding:1px 2px;}

</style>
{/block}
{block name="right_tab"}
<li><a class="nscs-table-handle_green" href="ADMIN_MAIN/Goods/addGoods.html"><i class="fa fa-plus-circle"></i>&nbsp;发布商品</a></li>
{/block}
{block name="main"}
<table class="mytable">
	<tr>
		<th style="line-height:33px;">
			创建时间：
			<input type="text" id="startDate" class="input-medium" placeholder="请选择开始日期" onclick="WdatePicker()" />
			&nbsp;-&nbsp;
			<input type="text" id="endDate" placeholder="请选择结束日期" class="input-medium" onclick="WdatePicker()" />
			商品名：<input id="goods_name" class="input-small" type="text" value="{$search_info}">
			上下架
			<select id="state">
				<option value="">全部</option>
				<option value="1">上架</option>
				<option value="0">下架</option>
				<option value="10">违规禁售</option>
			</select>	
			<input type="button" onclick="searchData()" value="搜索" />
		</th>
	</tr>
</table>
<div id="myTabContent" class="tab-content">
	<div class="tab-pane active">
		<table class="table table-striped table-main" border="0">
			<colgroup>
				<col style="width: 3%;">
				<col style="width: 25%;">
				<col style="width: 12%;">
				<col style="width: 9%;">
				<col style="width: 8%;">
				<col style="width: 7%;">
				<col style="width: 7%;">
				<col style="width: 15%;">
			</colgroup>
			<tbody>
				<tr class="table-title" style="background: white;z-index: 10;border: 1px solid #E3E3E3;">
					<th></th>
					<th>商品名称</th>
					<th>价格（元）</th>
					<th>总库存</th>
					<th>销量</th>
					<th>上下架</th>
					<th>排序</th>
					<th>操作</th>
				</tr>
				<tr class="trcss">
					<td colspan="5">
						<label style="display: inline-block;vertical-align: middle;">
							<input onclick="CheckAll(this)" id="ckall" type="checkbox">
							<span style="display: inline-block; margin-left: 0px; margin-right: 10px;font-weight: 400;">全选</span>
						</label>
						<a class="btn btn-small fun-a" href="javascript:void(0)" onclick="deleteGoodsCount()">删除</a>
						<a class="btn btn-small fun-a upstore" href="javascript:void(0)" onclick="goodsIdCount('online')">上架</a>
						<a class="btn btn-small fun-a downstore" href="javascript:void(0)" onclick="goodsIdCount('offline')">下架</a>
						<a class="btn btn-small fun-a recommend" href="javascript:void(0)"
						onclick="ShowRecommend()" data-html="true" id="setRecommend" title="<h6 class='edit-group-title'>推荐</h6>"
						data-container="body" data-placement="bottom"  data-trigger="manual"
						data-content="<div class='edit-group' id='recommendType'>
 							  <label class='checkbox-inline'><input type='checkbox' value='1'>热销 </label>
							  <label class='checkbox-inline'><input type='checkbox' value='2'>推荐 </label>
							  <label class='checkbox-inline'><input type='checkbox' value='3'>新品 </label>
							</div>
							<button class='edit-group-button group-button-bg' onclick='setRecommend();'>保存</button>
							<button class='edit-group-button' onclick='hideSetRecommend()'>取消</button>"
						>推荐</a>
						<a onclick="goodsGroupIdCount();"data-html="true"class="btn btn-small fun-a category" href="javascript:void(0)" id="editGroup" title="<h6 class='edit-group-title'>修改分组</h6>"  
							data-container="body" data-placement="bottom"  data-trigger="manual"
							data-content="<div class='edit-group' id='goodsChecked' style='max-width:auto;'>
 							{foreach $goods_group as $vo} 
 							<p>
 								<label class='checkbox-inline' style='display:inline-block;' >
								<input type='checkbox' value='{$vo.group_id}'><b>{$vo.group_name}</b>&nbsp;&nbsp;&nbsp;
								</label>
								{foreach $vo['sub_list']['data'] as $vs}
								<label style='display:inline-block;'>
								<input type='checkbox' value='{$vs.group_id}'>{$vs.group_name}
								</label>
								{/foreach}
							</p>
							{/foreach}
							</div>
							<button class='edit-group-button group-button-bg' onclick='goodsGroupUpdate();'>保存</button>
							<button class='edit-group-button' onclick='hideEditGroup()'>取消</button>">
							商品分组</a> 
							<input type='hidden'value='' id='goods_type_ids'/>
				</tr>
			</tbody>
			<tbody id="productTbody" style="border: 0px;">
				<tr class="table-title" style="display: none;">
					<th><label><input onclick="CheckAll(event)" id="ckall" name="" value="" type="checkbox"></label></th>
					<th>商品名称</th>
					<th>价格（元）</th>
					<th>总库存</th>
					<th>销量</th>
					<th>上下架</th>
					<th>排序</th>
					<th>操作</th>
				</tr>
			</tbody>
		</table>
	</div>
</div>
{/block} {block name="script"}
{include file="admin/b2c/pageCommon" /}
{include file="admin/b2c/openDialog" /}
<script type="text/javascript">
	//查询
	function searchData(){
		LoadingInfo(1);
	}
	/**
	 * 隐藏商品分组
	 */
	function hideEditGroup(){
		$("#editGroup").popover("hide");
	}
	function hideSetRecommend(){
		$("#setRecommend").popover("hide");
	}
	//查询用户列表
	function LoadingInfo(pageIndex) {
		var start_date = $("#startDate").val();
		var end_date = $("#endDate").val();
		var state = $("#state").val();
		var goods_name =$("#goods_name").val();
		$.ajax({
			type : "post",
			url : "ADMIN_MAIN/Goods/goodsList",
			async : true,
			data : {
				"pageIndex" : pageIndex,
				"start_date":start_date,
				"end_date":end_date,
				"state":state,
				"goods_name":goods_name
			},
			success : function(data) {
				$("#page_count").val(data["page_count"]);
				$("#pageNumber a").remove();
				var html = '';
				if (data["data"].length > 0) {
					for (var i = 0; i < data["data"].length; i++) {
						html += '<tr class="tr-title" style=" width: 1502px;"><td class="td-'+ data["data"][i]["goods_id"]+'"><label><input value="'
								+ data["data"][i]["goods_id"]
								+ '" tj="" name="sub" data-state="'+data["data"][i]["state"]+'" type="checkbox"></label></td>';
						html += '<td colspan="7" style="width: 97%;"><div style="display: inline-block; width: 100%;" class="pro-code"><span>商家编码：'
								+ data["data"][i]["code"] + '</span>';
								/* if(data["data"][i]["state"] == 1){
									html += '<span class="pro-code" style="color: #f35252; float: right;"> <i class="fa fa-long-arrow-up" style="margin-right: 4px;"></i>已上架';
								}else{
										html += '<span class="pro-code" style="color: #27A9E3; float: right;"> <i class="fa fa-long-arrow-up" style="margin-right: 4px;"></i>已下架';
								} */
						html += '<span class="pro-code" style="margin-left:10px;"><i class="fa fa-long-arrow-up" style="margin-right: 4px;"></i>创建时间：'+data["data"][i]["create_time"];
						html += '</span></div></td></tr>';
						html += '<tr><td colspan="2" style="background: white;"><div><a class="a-pro-view-img" href="APP_MAIN/Goods/goodsDetail.html?id='+data["data"][i]["goods_id"]+'"target="_blank"><img class="thumbnail-img"src="__ROOT__/'+data["data"][i]["pic_cover_micro"]+'">';
						html += '<div class="div-pro-view-name"><span style="color: #13A5D5;" class="thumbnail-name title='+ data["data"][i]["goods_name"]+'"><a "target="_blank" href="APP_MAIN/Goods/goodsDetail.html?id='+data["data"][i]["goods_id"]+'">'
								+ data["data"][i]["goods_name"]
								+ '</a></span>';
						//html += '<div class="div-flag-style"><span class="" title=""><i class="icon-tablet"style="background: none; color: #555; font-size: 20px; margin-right: 0;"></i></span><span onmouseover="mouseover(this)" onmouseout="mouseout(this)"style="display: inline-block;"> <i class="icon-qrcode"style="background: none; color: #555; font-size: 20px; margin-right: 0;"></i></span>';
						//html += '<div class="QRcode" style="display: none; position: absolute;"id="qrcode"><p><img src=""></p></div></div>';
						html += '</div><div style="margin-top:10px;">';
						html += data["data"][i]["is_hot"] == 1 ? '<i class="hot">热</i>' : '';
						html += data["data"][i]["is_recommend"] == 1 ? '<i class="recommend">荐</i>' : '';
						html += data["data"][i]["is_new"] == 1 ? '<i class="new">新</i>' : '';
						html += '</div></div></td>';
						html += '<td style="background: white;"><div class="priceaddactive"><span class="price-lable">单&nbsp;&nbsp;&nbsp;&nbsp;价</span><spanclass="price-numble" style="color: #666;"id="moreChangePrice'+ data["data"][i]["goods_id"]+'"  >'
								+ data["data"][i]["price"]
								+ '</span></div>';
						html += '<div><span class="price-lable" >活动价:</span><span class="price-numble"id="moreChangePrice'+ data["data"][i]["goods_id"]+'" style="color:red;">'
								+ data["data"][i]["promotion_price"]
								+ '</span>';
						html += '</td>';
						html += '<td style="background: white;"><div class="cell"><span class="pro-stock" style="color: #666;"id="moreChangeStock'+ data["data"][i]["goods_id"] + '">'
								+ data["data"][i]["stock"]
								+ '</span></div></td>';
						html += '<td style="background: white;"><div class="cell"><span class="pro-stock" style="color: #666;"id="moreChangeStock'+ data["data"][i]["goods_id"]+'">'
								+ data["data"][i]["real_sales"]
								+ '</span></div></td>';
						if(data["data"][i]["state"] == 1){
							html += '<td style="background: white;">已上架</td>';
						}else{
							html += '<td style="background: white;">已下架</td>';
						}
						html += '<td style="background: white;"><div class="cell"><span class="price-numble" onclick="oneChangeSort(this)">'
								+ data["data"][i]["sort"]
								+ '</span><input class="input-mini" pid="'
								+ data["data"][i]["goods_id"]
								+ '" style="display: none"value="'
								+ data["data"][i]["sort"]
								+ '" onblur="changeSort(this)" oldsort="'
								+ data["data"][i]["sort"]
								+ '" type="number"></div></td>';
						html += '<td style="background: white;"><div class="cell"><div class="bs-docs-example tooltip-demo"style="text-align: center;">';
						html += '<a href="javascript:;" data-placement="bottom" data-original-title="编辑"><span class="edit" style="display: inline-block; width: 19%;" onclick="updateGoodsDetail('
								+ data["data"][i]["goods_id"]
								+ ')"><i class="icon-edit" style="width: initial;"></i>编辑</span></a>';
						html += '<a href="javascript:void(0)" data-placement="bottom"onclick="deleteGoods('
								+ data["data"][i]["goods_id"]
								+ ')" data-original-title="删除"><span class="del" style="display: inline-block; width: 19%;"><i class="icon-trash" style="width: initial;"></i>删除</span></a></div></div></td></tr>';
					}
				} else {
					html += '<tr align="center"><th colspan="9">暂无符合条件的数据记录</th></tr>';
				}
				$("#productTbody").html(html);
				var totalpage = $("#page_count").val();
				if (totalpage == 1) {
					changeClass("all");
				}
				var $html = pagenumShow(jumpNumber,totalpage,{$pageshow})
				$("#pageNumber").append($html);
			}
		});
	}
	//把值传过去即可
	function updateGoodsDetail(goods_id) {
		window.location = "ADMIN_MAIN/Goods/addGoods?step=2&goodsId="
				+ goods_id;
	}
	function deleteGoodsCount() {
		var goods_ids= "";
		$("#productTbody input[type='checkbox']:checked").each(function() {
			if (!isNaN($(this).val())) {
				goods_ids = $(this).val() + "," + goods_ids;
			}
		});
		goods_ids = goods_ids.substring(0, goods_ids.length - 1);
		if(goods_ids == ""){
			$( "#dialog" ).dialog({
	            buttons: {
	                "确定,#51A351": function() {
	                    $(this).dialog('close');
	                }
	            },
	            contentText:"请选择需要操作的记录",
	            title:"消息提醒",
	        });
			return false;
		}
		deleteGoods(goods_ids);
		/* var del = confirm("确定要删除吗？"); */
		
		/* if (del) {			
			alert("確定啊，id我都有了，你看" + id);
		} else {
			alert("不確定");
		} */
	}
	//全选
	function CheckAll(event){
		var checked = event.checked;
		$("#productTbody input[type = 'checkbox']").prop("checked",checked);
		
	}
	//商品上架id合计
	function goodsIdCount(line){
		var goods_ids= "";
		$("#productTbody input[type='checkbox']:checked").each(function() {
			if (!isNaN($(this).val())) {
				var state = $(this).data("state");
				if(line == "online"){
					if(state == 1){
						$( "#dialog" ).dialog({
				            buttons: {
				                "确定,#51A351": function() {
				                    $(this).dialog('close');
				                }
				            },
				            contentText:"记录中包含已上架记录",
				            title:"消息提醒",
				        });
						return false;
					}
				}else{
				if(state == 0){
					$( "#dialog" ).dialog({
			            buttons: {
			                "确定,#51A351": function() {
			                    $(this).dialog('close');
			                }
			            },
			            contentText:"记录中包含已下架记录",
			            title:"消息提醒",
			        });
					return false;
					}
				}
				goods_ids = $(this).val() + "," + goods_ids;
			}
		});
		goods_ids = goods_ids.substring(0, goods_ids.length - 1);
		if(goods_ids == ""){
			$( "#dialog" ).dialog({
	            buttons: {
	                "确定,#51A351": function() {
	                    $(this).dialog('close');
	                }
	            },
	            contentText:"请选择需要操作的记录",
	            title:"消息提醒",
	        });
			return false;
		}
		modifyGoodsOnline(goods_ids,line);
	}
	
	//商品上下架
	function modifyGoodsOnline(goods_ids,line){
		if(line == "online"){
			var url = "ModifyGoodsOnline";
			var lingStr = "上架";
		}else{
			var url = "ModifyGoodsOffline";
			var lingStr = "下架";
		}
		$.ajax({
			type : "post",
			url : "ADMIN_MAIN/Goods/"+url,
			async : true,
			data : {
				"goods_ids" : goods_ids
			},
			success : function(data) {
				if(data["code"] > 0 ){
					LoadingInfo(1);
					$( "#dialog" ).dialog({
			            buttons: {
			                "确定,#51A351": function() {
			                    $(this).dialog('close');
			                }
			            },
			            contentText:"商品"+lingStr+"成功",
			            title:"消息提醒",
			      		time:5
			        });
				}
			}
		})
	}
	
	function deleteGoods(goods_ids){
		$( "#dialog" ).dialog({
            buttons: {
                "确定,#51A351": function() {
                    $(this).dialog('close');
                    $.ajax({
            			type : "post",
            			url : "ADMIN_MAIN/Goods/deleteGoods",
            			async : true,
            			data : {
            				"goods_ids" : goods_ids
            			},
    					dataType : "json",
            			success : function(data) {
            				if(data["code"] > 0 ){
            					LoadingInfo(1);
            					$( "#dialog" ).dialog({
            			            buttons: {
            			                "确定,#51A351": function() {
            			                    $(this).dialog('close');
            			                }
            			            },
            			            modal: true,
            			            contentText:data["message"],
            			            title:"消息提醒",
            			      		time:5
            			        });
            				}
            			}
            		})
                }
            },
            contentText:"你确定删除吗？",
            title:"消息提醒"
        });
	}
	//商品修改分组id合计
	function goodsGroupIdCount(){
		var goods_ids= "";
		$("#productTbody input[type='checkbox']:checked").each(function() {
			if (!isNaN($(this).val())) {
				goods_ids = $(this).val() + "," + goods_ids;
			}
		});
		goods_ids = goods_ids.substring(0, goods_ids.length - 1);
		if(goods_ids == ""){
			$( "#dialog" ).dialog({
	            buttons: {
	                "确定,#51A351": function() {
	                    $(this).dialog('close');
	                }
	            },
	            contentText:"请选择需要操作的记录",
	            title:"消息提醒",
	        });
			return false;
		}
		$("#goods_type_ids").val(goods_ids);
		$("#editGroup").popover("show");
		$(".popover").css("max-width",'1000px');
	}
	//商品修改分组
	function goodsGroupUpdate(){
		var goods_type = "";
		var goods_ids = $("#goods_type_ids").val();
		$("#goodsChecked input[type='checkbox']:checked").each(function(){
			if (!isNaN($(this).val())) {
				goods_type = $(this).val() + "," + goods_type;
			}
		})
		if(goods_type == ""){
			$( "#dialog" ).dialog({
	            buttons: {
	                "确定,#51A351": function() {
	                    $(this).dialog('close');
	                }
	            },
	            contentText:"请选择需要操作的记录",
	            title:"消息提醒",
	        });
			return false;
		}
		goods_type = goods_type.substring(0, goods_type.length - 1);
		$.ajax({
			type : "post",
			url : "ADMIN_MAIN/Goods/ModifyGoodsGroup",
			async : true,
			data : {
				"goods_id" : goods_ids,
				"goods_type" : goods_type
			},
			success : function(data) {
				if(data["code"] > 0 ){
					$("#editGroup").popover("hide");
					LoadingInfo(1);
					$( "#dialog" ).dialog({
			            buttons: {
			                "确定,#51A351": function() {
			                    $(this).dialog('close');
			                }
			            },
			            contentText:data["message"],
			            title:"消息提醒",
			        });
				} 
			}
		})
	}
//显示 推荐选项
function ShowRecommend(){
	var goods_ids= "";
	$("#productTbody input[type='checkbox']:checked").each(function() {
		if (!isNaN($(this).val())) {
			goods_ids = $(this).val() + "," + goods_ids;
		}
	});
	goods_ids = goods_ids.substring(0, goods_ids.length - 1);
	if(goods_ids == ""){
		$( "#dialog" ).dialog({				
            buttons: {
                "确定,#51A351": function() {
                    $(this).dialog('close');
                }
            },
            contentText:"请选择需要操作的记录",
            title:"消息提醒",
        });
		return false;
	}
	$("#goods_type_ids").val(goods_ids);
	$("#setRecommend").popover("show");
} 
//修改为  推荐 商品
function setRecommend(){
	var recommend_type = '';
	var goods_ids = $("#goods_type_ids").val();
	$("#recommendType input[type='checkbox']").each(function(){
		if ($(this).attr("checked") == 'checked') {
			var recommend_type_new = 1;
		}else{
			var recommend_type_new = 0;
		}
		recommend_type = recommend_type_new + "," + recommend_type;
	})
	if(recommend_type == ""){
		$( "#dialog" ).dialog({
            buttons: {
                "确定,#51A351": function() {
                    $(this).dialog('close');
                }
            },
            contentText:"请选择需要操作的记录",
            title:"消息提醒",
        });
		return false;
	}
	recommend_type = recommend_type.substring(0, recommend_type.length - 1);
	$.ajax({
		type : "post",
		url : "ADMIN_MAIN/Goods/ModifyGoodsRecommend",
		async : true,
		data : {
			"goods_id" : goods_ids,
			"recommend_type" : recommend_type
		},
		success : function(data) {
			if(data["code"] > 0 ){
				$("#setRecommend").popover("hide");
				LoadingInfo(1);
				$( "#dialog" ).dialog({
		            buttons: {
		                "确定,#51A351": function() {
		                    $(this).dialog('close');
		                }
		            },
		            contentText:data["message"],
		            title:"消息提醒",
		        });
			} 
		}
	})
}
</script>
{/block}